package com.banyuan.servlet;

import com.banyuan.dao.UserUtils;
import com.banyuan.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user/find")
public class FindServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String str = req.getParameter("name");
        if (str != null && !(str.trim().equals(""))) {
            List<User> findList = UserUtils.findUser(str.trim());
            // tirm  给String去除空格
            req.setAttribute("userList",findList);
            req.getRequestDispatcher("/WEB-INF/user/list.jsp").forward(req,resp);
        } else {
            resp.sendRedirect(req.getContextPath()+"/user/list");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
